package com.rightsidetech.http.controller.storeApp.home;

import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.utils.DateUtil;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.response.store.StoreAppHomeResp;
import com.rightsidetech.system.service.SysStoreIntegralService;
import com.rightsidetech.system.service.SysStoreStorkService;
import com.rightsidetech.trade.service.TdCommodityUserOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;


@RestController
@RequestMapping("/storeApp/home")
@ShenyuSpringMvcClient(path = "/storeApp/home/**")
@Api(tags = "门店首页相关")
public class HomeStoreAppController extends BaseController {

    @Resource
    private TdCommodityUserOrderService tdCommodityUserOrderService;
    @Resource
    private SysStoreIntegralService sysStoreIntegralService;
    @Resource
    private SysStoreStorkService sysStoreStorkService;

    @Log
    @Token
    @ApiOperation("首页数据展示")
    @PostMapping("/data")
    public ResponseData<StoreAppHomeResp> data(){
        StoreAppHomeResp storeAppHomeResp = new StoreAppHomeResp();
        Long totalOrderNum = tdCommodityUserOrderService.selectFinishTotalOrderNumByStoreId(Long.parseLong(getAttribute()));
        storeAppHomeResp.setTotalOrderNum(totalOrderNum);
        Long todayOrderNum = tdCommodityUserOrderService.selectFinishTodayOrderNumByStoreId(Long.parseLong(getAttribute()));
        storeAppHomeResp.setTodayOrderNum(todayOrderNum);
//        Long todayPointAmount = sysStoreIntegralService.findIntegralByDate(DateUtil.getDate(new Date()),Long.parseLong(getAttribute()));
        Long totalPointAmount = sysStoreIntegralService.findCurrentPointByStoreId(Long.parseLong(getAttribute()));
//        storeAppHomeResp.setTodayPointAmount(todayPointAmount);
        storeAppHomeResp.setTotalPointAmount(totalPointAmount);
        Long currentStock = sysStoreStorkService.findStoreCurrentStock(Long.parseLong(getAttribute()));
        Long confirmStock = sysStoreStorkService.findConfirmStock(Long.parseLong(getAttribute()));
        storeAppHomeResp.setCurrentStock(currentStock);
        storeAppHomeResp.setConfirmStock(confirmStock);
        return ResponseData.success(storeAppHomeResp);
    }
}
